<?php
require_once PHP_UI_PATH . DS . 'UIControl.php';
require_once PHP_UI_PATH . DS . 'DataSet.php';

/**
 * Description of Radio
 *
 * @author JeyDotC
 */
class Radio extends DataSetUIControl implements DataSet {

    private $options = array();

    public function getOptions() {
        return $this->options;
    }

    public function setOptions(array $options) {
        $this->options = $options;
    }

    protected function getControlRendering() {
        $render = "";

        $valor = $this->getValue();
        $i = 0;
        $primeraOpcion = "";

        foreach ($this->getOptions() as $value => $opcion) {
            $seleccionado = "";

            if ($valor == $opcion || $i == 0) {
                $seleccionado = "checked='checked'";
            }
            
            if($this->getOptionsLayout() == OptionsLayouts::VERTICAL){
                $render .= "<div>";
            }
            
            $render .= "<input type='radio' value='$value' $seleccionado name='{$this->getName()}' id='_{$this->getName()}_$i' /> <label for='_{$this->getName()}_$i'>$opcion</label> ";
            
            if($this->getOptionsLayout() == OptionsLayouts::VERTICAL){
                $render .= "</div>";
            }
            $i++;
        }

        return $render;
    }

}

?>
